<?include_once('conn.php');?>
<?include_once('inc_head.php');?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?
$act=$_GET['act'];
$series=isset($series)?$series:0;
$listTable = TABLE_C."company";

#/////////////////////////删除/////////////////////
if($act=='del') {	
	$id=addslashes($_GET['id']); 
	//从数据数据库
	$cmd="delete from $listTable where id=".$id;
	if(mysql_query($cmd) or die(mysql_error())){
		gourl('删除成功！',$cururl);	
	}
	exit;
}
?>
<body>
	<?local("公司列表");?>
<div id="intro">
<!-------------------------------------默认状态------------------------------------->
<table width="100%" border="0"  cellpadding="2" cellspacing="0">
  <tr> 
      <td width="50%"> 
		    <?
			#显示排序
			echo " <a href='?sid=$series&okey=id asc' class='btn btn-md btn-default'>ID▲</a> ";
			echo " <a href='?sid=$series&okey=id desc' class='btn btn-md btn-default'>ID▼</a>";
		    ?>
       </td>
			
      <td width="50%" align=right> 
        <?	
        $okey=get2('okey');
		$page=intval($_GET['page']);
		if($page==0){$page=1;}
		$pagesize=$news_pagesize;
		$rsStar=$page*$pagesize-$pagesize;
		
		//总数
		$cmd="select  id from $listTable  ";
		$rs=mysql_query($cmd) or die(mysql_error());
		$rstotal=mysql_num_rows($rs);
		
		//排序整理
		$orderTxt=" order by c.$okey";
		if($okey==''){
			$orderTxt=' order by c.id desc';
		}
		/*
		$cmd="select c.*,coalesce(u.count,0) staff from $listTable  c 
		left join(select count(*) count,id,unionid,company from {$TABLE}user group by company ) u on u.company=c.id 
		" .$orderTxt." LIMIT $rsStar,$pagesize";
		*/

		$cmd = "
		select 
			c.*,
			c_qn.all_qn_count,
			coalesce(u.count,0) staff 
		from {$TABLE}company c
		left join(
			select sum(qn.count) all_qn_count,u.company from {$TABLE}user u
			left join(select count(id) count,id,unionid from {$TABLE}vote_qn group by unionid) qn on qn.unionid=u.unionid
			group by company
		) c_qn on c_qn.company = c.id
		left join(select count(*) count,id,unionid,company from {$TABLE}user group by company ) u on u.company=c.id 
		";

		$rs=mysql_query($cmd) or die(mysql_error());	
		$pagetotal=ceil($rstotal/$pagesize);
		echo "<div>当前分类记录数共【".$rstotal."】条,每页显示【".$pagesize."】条 ,页码：$page/$pagetotal</div>";
		
		?>
	  </td>
          </tr>
        </table>
	<!--主内容表格-->
<form name="form_all" method=post action="?act=doall" style="margin:0px">
  <table class="table table-hover table-bordered table-striped" width="100%" border="0"  cellpadding="0" cellspacing="0" >
    <tr> 
      <th width="30"  >&nbsp;</th>
      <th width="70"  >ID</th>
      <th width="400" >标题</th>
      <th width="" >省</th>
      <th width="" >市</th>
      <th width="" >县区</th>
      <th width="" >园区</th>
      <th width="" >完整地区</th>
      <th width="100" >公司规模</th>
      <th width="100" >注册员工数</th>
      <th width="100" >问卷数</th>
      <th width="150"  >操作</th>
    </tr>
    <?
	while($row=mysql_fetch_assoc($rs)){
	  $id=$row['id'];
  ?>
    <tr  class="mytr" > 
      <td align=""  > <input type=checkbox value="<? echo $id ?>" name="checkbox[]"></td>
      <td align="" ><? echo $id ?></td>
      <td align=""><? echo $row['title'];?></td>
	  <td align=""><? echo $row['province'];?></td>
	  <td align=""><? echo $row['city'];?></td>
	  <td align=""><? echo $row['area'];?></td>
	  <td align=""><? echo $row['scope'];?></td>
	  <td align=""><? echo $row['full_addr'];?></td>
      <td align=""><? echo $row['size'];?></td>
      <td align="center"><? echo $row['staff'];?></td>
      <td align="center"><? echo $row['all_qn_count'];?></td>
      <td align="center" > 
		<!-- <a href="admin_vote_edit.php?id=<?echo $id?>" class="btn btn-xs btn-info" rel="floatEdit" target="_blank">编辑</a>  -->
		<a href="admin_user.php?company=<?echo $row['id']?>" class="btn btn-xs btn-info" rel="floatEdit__" target="_blank">员工</a>
		<a href="admin_questionneair_c.php?company=<?echo $row['id']?>" class="btn btn-xs btn-info" rel="floatEdit__" target="_blank">问卷</a>
		
 		<a  href="javascript:if(confirm('确定吗')){window.location='?act=del&id=<?echo $id?>&vfile=<? echo $row['videofile'];?>&imgf=<?echo $row['imagefile'];?>'}" class="btn btn-xs btn-danger">删除</a> 
       </td>
    </tr>
    <?}?>
  </table>

  <!--下面的控制表格-->
  <table width="100%" border="0"  cellpadding="5" cellspacing="0">
	<tr>
	<td width="50%" >
		&nbsp;
	</td>
	<td width="" align=right><? echo turnpage2($pagesize,$rstotal);?></td>
	</tr>
  </table>
  </form>
  
<?include('inc_foot.php');?>
</div>
</body>
</html>